package com.itany.book.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itany.book.book.service.BookTypeService;
import com.itany.book.pojo.BookType;
import com.itany.book.vo.ActionResult;
import com.itany.book.vo.ResponseResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述:
 * 日期:2020年01月04日 上午11:03
 * 作者:soft01
 * 版本:1.0
 */
@RestController
@RequestMapping("/bookTypes")
public class BookTypeController {

    @Reference
    private BookTypeService bookTypeService;

    @RequestMapping("/findAll")
    public ResponseResult findAll(){
        List<BookType> bookTypes = bookTypeService.findAll();

        return ResponseResult.success(bookTypes);
        // return ActionResult.success(bookTypes);
    }

    @RequestMapping("/findOne")
    public ResponseResult findOne(){
        List<BookType> bookTypes = bookTypeService.findOne();
        Map<String,Object> result = new HashMap<>();
        for(BookType b : bookTypes){
            List<Map<String,Object>> res = new ArrayList<>();
            for(BookType b2 : b.getBookTypes()){
                Map<String,Object> r2 = new HashMap<>();
                r2.put("name",b2.getTypetext());
                List<String> r3 = new ArrayList<>();
                for(BookType b3 : b2.getBookTypes()){
                    r3.add(b3.getTypetext());
                }
                r2.put("content",r3);
                res.add(r2);
            }
            result.put(String.valueOf(b.getId()),res);
        }
        return ResponseResult.success(result);
        // return ActionResult.success(result);
    }

}
